package com.example.hookams

import android.content.Context
import android.content.SharedPreferences

const val SP_NAME = "LOGIN_LOG"

object LoginUtil {
    var share: SharedPreferences? = null

    fun init(context: Context) {
        share = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
        val edit = share?.edit()
    }

    fun isLogin(): Boolean {
        return share?.getBoolean("login", false) ?: false
    }

    fun saveLoginState(userName: String) {
        share?.edit()?.apply {
            putString("name", userName)
            putBoolean("login", true) //设置保存的数据
        }?.apply()
    }

    fun logout() {
        share?.edit()?.apply {
            putBoolean("login", false)
        }?.apply()
    }
}
